using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VAMSEQ
    {
        public DataRow Convert2AMSEQ(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryAMSEQ(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AMSQMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AMSQMNRKRS"] = " ".PadRight(2 ); 
         dwReturn["AMSQMLFDNR"] = " ".PadRight(4 ); 
         dwReturn["AMSQMPOS"] = " ".PadRight(2 ); 
         dwReturn["AMSQSEQNR"] = " ".PadRight(0 ); 
         dwReturn["AMSQAENZL"] = " ".PadRight(0 ); 
         dwReturn["AMSQAENB"] = " ".PadRight(8 ); 
         dwReturn["AMSQAEND"] = " ".PadRight(0 ); 
         dwReturn["AMSQNEUB"] = " ".PadRight(8 ); 
         dwReturn["AMSQNEUD"] = " ".PadRight(0 ); 
         dwReturn["AMSQNEUZ"] = " ".PadRight(0 ); 
         dwReturn["AMSQGEBNR"] = " ".PadRight(8 ); 
         dwReturn["AMSQLAGE"] = " ".PadRight(2 ); 
         dwReturn["AMSQRWKRS"] = " ".PadRight(2 ); 
         dwReturn["AMSQRWLFD"] = " ".PadRight(6 ); 
         dwReturn["AMSQRWPOS"] = " ".PadRight(4 ); 
         dwReturn["AMSQKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["AMSQSTKNR"] = " ".PadRight(12 ); 
         dwReturn["AMSQMENGE"] = " ".PadRight(0 ); 
         dwReturn["AMSQFILLER"] = " ".PadRight(110 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapAMSEQ(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveAMSEQ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryAMSEQ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapAMSEQ(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertAMSEQ(dwLocal, ITXDBVERSION);
            }
            UpdateAMSEQ(dwLocal);
        }
        public void InsertAMSEQ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO AMSEQ(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryAMSEQ(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM AMSEQ WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM AMSEQ  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "AMSEQ";
            Return = Result;
            return Return;
        }
        public void DeleteAMSEQ(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM AMSEQ   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateAMSEQ(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE AMSEQ SET "
                    +"AMSQMANDANT= :AMSQMANDANT,"
                    +"AMSQMNRKRS= :AMSQMNRKRS,"
                    +"AMSQMLFDNR= :AMSQMLFDNR,"
                    +"AMSQMPOS= :AMSQMPOS,"
                    +"AMSQSEQNR= :AMSQSEQNR,"
                    +"AMSQAENZL= :AMSQAENZL,"
                    +"AMSQAENB= :AMSQAENB,"
                    +"AMSQAEND= :AMSQAEND,"
                    +"AMSQNEUB= :AMSQNEUB,"
                    +"AMSQNEUD= :AMSQNEUD,"
                    +"AMSQNEUZ= :AMSQNEUZ,"
                    +"AMSQGEBNR= :AMSQGEBNR,"
                    +"AMSQLAGE= :AMSQLAGE,"
                    +"AMSQRWKRS= :AMSQRWKRS,"
                    +"AMSQRWLFD= :AMSQRWLFD,"
                    +"AMSQRWPOS= :AMSQRWPOS,"
                    +"AMSQKUNDNR= :AMSQKUNDNR,"
                    +"AMSQSTKNR= :AMSQSTKNR,"
                    +"AMSQMENGE= :AMSQMENGE,"
                    +"AMSQFILLER= :AMSQFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AMSQMANDANT", OracleType.NVarChar).Value = dwData["AMSQMANDANT"].ToString(); 
          or1.Parameters.Add("AMSQMNRKRS", OracleType.NVarChar).Value = dwData["AMSQMNRKRS"].ToString(); 
          or1.Parameters.Add("AMSQMLFDNR", OracleType.NVarChar).Value = dwData["AMSQMLFDNR"].ToString(); 
          or1.Parameters.Add("AMSQMPOS", OracleType.NVarChar).Value = dwData["AMSQMPOS"].ToString(); 
          or1.Parameters.Add("AMSQSEQNR", OracleType.NVarChar).Value = dwData["AMSQSEQNR"].ToString(); 
          or1.Parameters.Add("AMSQAENZL", OracleType.NVarChar).Value = dwData["AMSQAENZL"].ToString(); 
          or1.Parameters.Add("AMSQAENB", OracleType.NVarChar).Value = dwData["AMSQAENB"].ToString(); 
          or1.Parameters.Add("AMSQAEND", OracleType.NVarChar).Value = dwData["AMSQAEND"].ToString(); 
          or1.Parameters.Add("AMSQNEUB", OracleType.NVarChar).Value = dwData["AMSQNEUB"].ToString(); 
          or1.Parameters.Add("AMSQNEUD", OracleType.NVarChar).Value = dwData["AMSQNEUD"].ToString(); 
          or1.Parameters.Add("AMSQNEUZ", OracleType.NVarChar).Value = dwData["AMSQNEUZ"].ToString(); 
          or1.Parameters.Add("AMSQGEBNR", OracleType.NVarChar).Value = dwData["AMSQGEBNR"].ToString(); 
          or1.Parameters.Add("AMSQLAGE", OracleType.NVarChar).Value = dwData["AMSQLAGE"].ToString(); 
          or1.Parameters.Add("AMSQRWKRS", OracleType.NVarChar).Value = dwData["AMSQRWKRS"].ToString(); 
          or1.Parameters.Add("AMSQRWLFD", OracleType.NVarChar).Value = dwData["AMSQRWLFD"].ToString(); 
          or1.Parameters.Add("AMSQRWPOS", OracleType.NVarChar).Value = dwData["AMSQRWPOS"].ToString(); 
          or1.Parameters.Add("AMSQKUNDNR", OracleType.NVarChar).Value = dwData["AMSQKUNDNR"].ToString(); 
          or1.Parameters.Add("AMSQSTKNR", OracleType.NVarChar).Value = dwData["AMSQSTKNR"].ToString(); 
          or1.Parameters.Add("AMSQMENGE", OracleType.NVarChar).Value = dwData["AMSQMENGE"].ToString(); 
          or1.Parameters.Add("AMSQFILLER", OracleType.NVarChar).Value = dwData["AMSQFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
